#include<bits/stdc++.h>
using namespace std;
int n,m,l,r,f[1000010],sm,ss,ans;
string s;
int main(){
	freopen("good.in","r",stdin);
	freopen("good.out","w",stdout);
	cin>>n>>m>>s,s=" "+s;
	while(m--){
		cin>>l>>r,sm=ss=0;
		for(int i=l;i<=r;i++){
			f[i]=0;
			if(s[i]=='0')ss--;
			else ss++;
			if(ss<0)f[i]=1,ss++,sm++;
		}
		ss=0;
		for(int i=r;i>=l;i--){
			if(s[i]=='0')ss--;
			else ss++;
			if(ss<0)ss++,sm++;
			if(f[i])ss++;
		}
		ans^=sm;
	}
	cout<<ans;
	return 0;
}
